package org.wj.problem;

import java.util.*;

public class LengthOfLongesSubstring {

	public static void main(String[] args) {
		int au = lengthOfLongestSubstring("au");
	}

	public static int lengthOfLongestSubstring(String s) {
		byte[] bytes = s.getBytes();
		Map<Byte, Integer> indexMap = new HashMap<>();
		int maxSize = 0;
		for (int i = 0; i < bytes.length; i++) {
			if (indexMap.containsKey(bytes[i])) {
				if (maxSize < indexMap.size()) {
					maxSize = indexMap.size();
				}
				i = indexMap.get(bytes[i]) + 1;
				indexMap.clear();
			}
			indexMap.put(bytes[i], i);
		}
		if (indexMap.size() > maxSize) {
			maxSize = indexMap.size();
		}
		return maxSize;
	}

}
